﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:hc_de_au
	/// </summary>
	public partial class hc_de_au
	{
		public hc_de_au()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.hc_de_au model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into hc_de_au(");
			strSql.Append("fid,mid,auname,ftype,ftdname,ffname,fclass,fmissingMessage,frequired,fdataoptions,fdatainfo,fordernum)");
			strSql.Append(" values (");
			strSql.Append("@fid,@mid,@auname,@ftype,@ftdname,@ffname,@fclass,@fmissingMessage,@frequired,@fdataoptions,@fdatainfo,@fordernum)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@fid", MySqlDbType.Double),
					new MySqlParameter("@mid", MySqlDbType.Double),
					new MySqlParameter("@auname", MySqlDbType.VarChar,50),
					new MySqlParameter("@ftype", MySqlDbType.VarChar,50),
					new MySqlParameter("@ftdname", MySqlDbType.VarChar,50),
					new MySqlParameter("@ffname", MySqlDbType.VarChar,50),
					new MySqlParameter("@fclass", MySqlDbType.VarChar,50),
					new MySqlParameter("@fmissingMessage", MySqlDbType.VarChar,50),
					new MySqlParameter("@frequired", MySqlDbType.VarChar,50),
					new MySqlParameter("@fdataoptions", MySqlDbType.VarChar,50),
					new MySqlParameter("@fdatainfo", MySqlDbType.VarChar,255),
					new MySqlParameter("@fordernum", MySqlDbType.Int32,11)};
			parameters[0].Value = model.fid;
			parameters[1].Value = model.mid;
			parameters[2].Value = model.auname;
			parameters[3].Value = model.ftype;
			parameters[4].Value = model.ftdname;
			parameters[5].Value = model.ffname;
			parameters[6].Value = model.fclass;
			parameters[7].Value = model.fmissingMessage;
			parameters[8].Value = model.frequired;
			parameters[9].Value = model.fdataoptions;
			parameters[10].Value = model.fdatainfo;
			parameters[11].Value = model.fordernum;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.hc_de_au model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update hc_de_au set ");
			strSql.Append("fid=@fid,");
			strSql.Append("mid=@mid,");
			strSql.Append("auname=@auname,");
			strSql.Append("ftype=@ftype,");
			strSql.Append("ftdname=@ftdname,");
			strSql.Append("ffname=@ffname,");
			strSql.Append("fclass=@fclass,");
			strSql.Append("fmissingMessage=@fmissingMessage,");
			strSql.Append("frequired=@frequired,");
			strSql.Append("fdataoptions=@fdataoptions,");
			strSql.Append("fdatainfo=@fdatainfo,");
			strSql.Append("fordernum=@fordernum");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@fid", MySqlDbType.Double),
					new MySqlParameter("@mid", MySqlDbType.Double),
					new MySqlParameter("@auname", MySqlDbType.VarChar,50),
					new MySqlParameter("@ftype", MySqlDbType.VarChar,50),
					new MySqlParameter("@ftdname", MySqlDbType.VarChar,50),
					new MySqlParameter("@ffname", MySqlDbType.VarChar,50),
					new MySqlParameter("@fclass", MySqlDbType.VarChar,50),
					new MySqlParameter("@fmissingMessage", MySqlDbType.VarChar,50),
					new MySqlParameter("@frequired", MySqlDbType.VarChar,50),
					new MySqlParameter("@fdataoptions", MySqlDbType.VarChar,50),
					new MySqlParameter("@fdatainfo", MySqlDbType.VarChar,255),
					new MySqlParameter("@fordernum", MySqlDbType.Int32,11)};
			parameters[0].Value = model.fid;
			parameters[1].Value = model.mid;
			parameters[2].Value = model.auname;
			parameters[3].Value = model.ftype;
			parameters[4].Value = model.ftdname;
			parameters[5].Value = model.ffname;
			parameters[6].Value = model.fclass;
			parameters[7].Value = model.fmissingMessage;
			parameters[8].Value = model.frequired;
			parameters[9].Value = model.fdataoptions;
			parameters[10].Value = model.fdatainfo;
			parameters[11].Value = model.fordernum;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hc_de_au ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hc_de_au GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select fid,mid,auname,ftype,ftdname,ffname,fclass,fmissingMessage,frequired,fdataoptions,fdatainfo,fordernum from hc_de_au ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			hcrainMvc.Model.hc_de_au model=new hcrainMvc.Model.hc_de_au();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hc_de_au DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.hc_de_au model=new hcrainMvc.Model.hc_de_au();
			if (row != null)
			{
					//model.fid=row["fid"].ToString();
					//model.mid=row["mid"].ToString();
				if(row["auname"]!=null)
				{
					model.auname=row["auname"].ToString();
				}
				if(row["ftype"]!=null)
				{
					model.ftype=row["ftype"].ToString();
				}
				if(row["ftdname"]!=null)
				{
					model.ftdname=row["ftdname"].ToString();
				}
				if(row["ffname"]!=null)
				{
					model.ffname=row["ffname"].ToString();
				}
				if(row["fclass"]!=null)
				{
					model.fclass=row["fclass"].ToString();
				}
				if(row["fmissingMessage"]!=null)
				{
					model.fmissingMessage=row["fmissingMessage"].ToString();
				}
				if(row["frequired"]!=null)
				{
					model.frequired=row["frequired"].ToString();
				}
				if(row["fdataoptions"]!=null)
				{
					model.fdataoptions=row["fdataoptions"].ToString();
				}
				if(row["fdatainfo"]!=null)
				{
					model.fdatainfo=row["fdatainfo"].ToString();
				}
				if(row["fordernum"]!=null && row["fordernum"].ToString()!="")
				{
					model.fordernum=int.Parse(row["fordernum"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select fid,mid,auname,ftype,ftdname,ffname,fclass,fmissingMessage,frequired,fdataoptions,fdatainfo,fordernum ");
			strSql.Append(" FROM hc_de_au ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM hc_de_au ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.fid desc");
			}
			strSql.Append(")AS Row, T.*  from hc_de_au T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hc_de_au";
			parameters[1].Value = "fid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

